const PkManageModule = require('../models/private_key_manage');
const AElfModule = require('../models/aelf')

const node_pk = '845dadc4609852818f3f7466b63adad0504ee77798b91853fdab6af80d3a4eba';

exports.form = (req, res) => {
    res.render('recharge', { title: '充值页面' });
};

exports.recharge = (req, res) => {
    const aelf = new AElfModule();

    const data = req.body;

    aelf.check_chain_state((state) => {
        if (state) {
            aelf.load_wallet(node_pk, (wallet) => {
                if (typeof (wallet) !== 'undefined') {
                    aelf.load_contract(false, (param) => {
                        console.log("contract prepared");
                        aelf.Recharge(param, data.receiver, data.amount);
                        res.redirect('back');
                    });
                }
            });
        }
    })


};

